﻿
goog.provide('ol.dmp.interactionGeometry.Base');


ol.dmp.interactionGeometry.Base = function (options)
{
    /**
     * 鼠标按下位置的坐标
     * @type {ol.Pixel}
     * @private
     */
    this.downPx_ = null;
    /**
     * Finish coordinate for the feature (first point for polygons, last point for
     * linestrings).
     * @type {ol.Coordinate}
     * @private
     */
    this.finishCoordinate_ = null;


    this.snapTolerance_ = 12;
    /**
     * Sketch feature.
     * @type {ol.Feature}
     * @private
     */
    this.sketchFeature_ = null;

    /**
     * Sketch point.
     * @type {ol.Feature}
     * @private
     */
    this.sketchPoint_ = null;

    /**
     * Sketch line. Used when drawing polygon.
     * @type {ol.Feature}
     * @private
     */
    this.sketchLine_ = null;


    /// 要素的关键点
    this.keyPoints_ = [];          // 里边填的值应该是以数组形式存在的。
};



ol.dmp.interactionGeometry.Base.prototype.atFinish = function (event)
{
    return true;
};

ol.dmp.interactionGeometry.Base.prototype.createOrUpdateSketchPoint = function (event)
{
    var coordinates = event.coordinate.slice();
    if (goog.isNull(this.sketchPoint_))
    {
        this.sketchPoint_ = new ol.Feature(new ol.geom.Point(coordinates));
    }
    else
    {
        var sketchPointGeom = this.sketchPoint_.getGeometry();
        sketchPointGeom.setCoordinates(coordinates);
    }
};

ol.dmp.interactionGeometry.Base.prototype.startDrawing = function (event)
{

};

ol.dmp.interactionGeometry.Base.prototype.modifyDrawing = function (event)
{

};

ol.dmp.interactionGeometry.Base.prototype.addToDrawing = function (event)
{

};

ol.dmp.interactionGeometry.Base.prototype.finishDrawing = function (event)
{
    this.keyPoints_.push(event.coordinate);   // 添加最后一个关键点
};

ol.dmp.interactionGeometry.Base.prototype.abortDrawing = function (event)
{
    this.finishCoordinate_ = null;
    var sketchFeature = this.sketchFeature_;
    var keypoints = this.keyPoints_;
    if (!goog.isNull(sketchFeature))
    {
        this.sketchFeature_ = null;
        this.sketchPoint_ = null;
        this.sketchLine_ = null;

        this.keyPoints_=[];
    }
    return {"feature":sketchFeature,"keypoints":keypoints};
};

ol.dmp.interactionGeometry.Base.prototype.getSketchPoint = function ()
{
    return this.sketchPoint_;
};

ol.dmp.interactionGeometry.Base.prototype.getSketchLine = function ()
{
    return this.sketchLine_;
};

ol.dmp.interactionGeometry.Base.prototype.getSketchRawPolygon = function ()
{
    return this.sketchRawPolygon_;
};

ol.dmp.interactionGeometry.Base.prototype.getSketchFeature = function ()
{
    return this.sketchFeature_;
};


